package org.phmanago.utils;

import java.io.File;
import java.io.FileFilter;
import java.util.Vector;

public class FileSystemManager {

	public static Vector<FileNode> getContent(File f) {
		Vector<FileNode> vector = new Vector<FileNode>();
		if (f.isDirectory()) {
			File[] tmp = f.listFiles(new ImageFileFilter());
			for (File i : tmp) {
				FileNode fsNode = new FileNode(i.getName(), i.length());
				fsNode.set_img(ThumbMaker.getThumb(i, 100, 100));
				vector.add(fsNode);
			}
		}
		
		return vector;
	}
}

class ImageFileFilter implements FileFilter {
    public boolean accept(File p) {
            if (p.isDirectory()) {
                return false;            
            }
          
            String tmp = p.getName().toLowerCase(); 

            if (tmp.endsWith(".gif") || tmp.endsWith(".png") ||
                    tmp.endsWith(".jpeg") || tmp.endsWith(".jpg") ||
                    tmp.endsWith(".jpe"))
                    return true;

            return false;
    }
}
